<link rel="stylesheet" type="text/css" href="<?php HTMLHelper::baseUrl() ?>css/admin.css" />
<script src="<?php HTMLHelper::baseUrl() ?>js/tinymce/jquery.tinymce.js"></script>
<div class="admin_back">
    <div class="admin_area">
    <h3><?php echo $creating ? "Alta de Producto" : "Modificación de Producto" ?></h3>
    <div class="commands"><a href="<?php HTMLHelper::baseUrl() ?>products/list">Volver</a></div>
    <form method="post" enctype="multipart/form-data">
    <?php if(!empty($product['id'])) echo('<input type="hidden" name="r[id]" value="'.$product['id'].'">');  ?>
    <table class="formulario_producto">
    
      <?php if(!empty($error['_general'])): ?>
      <tr class="error">
        <td colspan="3">ERROR: <?php echo $error['_general']; ?></td>
      </tr>
      <?php endif; ?>
      
      
      <tr <?php echo empty($error['nombre'])?'':'class="error"'; ?>>
        <td>Nombre</td>
        <td><input type="text" name="r[nombre]" value="<?php echo empty($product['nombre'])?'':$product['nombre']; ?>"></td>
      </tr>
      
      <tr <?php echo empty($error['imagen'])?'':'class="error"'; ?>>
        <td>Imagen</td>
        <td>
          <?php if(!empty($product['imagen'])) echo('<img src="'.Config::get('base_url', '/').'fotos/'.$product['imagen'].'">');  ?>
          <input type="file" name="imagen" accept="image/jpg, image/jpeg">
        </td>
      </tr>
      
      <tr <?php echo empty($error['link'])?'':'class="error"'; ?>>
        <td>URL para link en la imagen</td>
        <td>      
          <input type="text" name="r[link]" value="<?php echo empty($product['link'])?'':$product['link']; ?>">
        </td>
      </tr> 
           
      <?php if($showLab): ?>
      <tr <?php echo empty($error['laboratorio'])?'':'class="error"'; ?>>
        <td>Laboratorio</td>
        <td><input type="text" name="r[laboratorio]" value="<?php echo empty($product['laboratorio'])?'':$product['laboratorio']; ?>"></td>
      </tr>
      <?php endif; ?>
      
      <tr <?php echo empty($error['pais'])?'':'class="error"'; ?>>
        <td>Paises</td>
        <td><?php echo PaisHelper::checkboxProducto($paises); ?></td>
      </tr>
      
      <tr <?php echo empty($error['principioactivo'])?'':'class="error"'; ?>>
        <td>Principio Activo</td>
        <td><input type="text" name="r[principioactivo]" value="<?php echo empty($product['principioactivo'])?'':$product['principioactivo']; ?>"></td>
      </tr>
      
      <tr <?php echo empty($error['especie'])?'':'class="error"'; ?>>
        <td>Especies</td>
        <td><?php echo EspeciesHelper::checkboxProducto($especies); ?></td>
      </tr>
      
      <tr <?php echo empty($error['descripcion'])?'':'class="error"'; ?>>
        <td>Descripción</td>
        <td class="mce"><textarea name="r[descripcion]" class="html"><?php echo empty($product['descripcion'])?'':$product['descripcion']; ?></textarea></td>
      </tr>
      
      <tr <?php echo empty($error['indicacion2'])?'':'class="error"'; ?>>
        <td>Accion Listado</td>
        <td><input type="text" name="r[indicacion2]" value="<?php echo empty($product['indicacion2'])?'':$product['indicacion2']; ?>"></td>
      </tr>
      
      <tr <?php echo empty($error['indicacion'])?'':'class="error"'; ?>>
        <td>Accion Ficha</td>
        <td class="mce"><textarea name="r[indicacion]" class="html"><?php echo empty($product['indicacion'])?'':$product['indicacion']; ?></textarea></td>
      </tr>
      
      <tr <?php echo empty($error['detail1'])?'':'class="error"'; ?>>
        <td>Indicaciones</td>
        <td class="mce"><textarea name="r[detail1]" class="html"><?php echo empty($product['detail1'])?'':$product['detail1']; ?></textarea></td>
      </tr>
      
      <tr <?php echo empty($error['detail2'])?'':'class="error"'; ?>>
        <td>Presentación</td>
        <td class="mce"><textarea name="r[detail2]" class="html"><?php echo empty($product['detail2'])?'':$product['detail2']; ?></textarea></td>
      </tr>

      <tr <?php echo empty($error['detail3'])?'':'class="error"'; ?>>
        <td>Aplicación</td>
        <td class="mce"><textarea name="r[detail3]" class="html"><?php echo empty($product['detail3'])?'':$product['detail3']; ?></textarea></td>
      </tr>

      <tr <?php echo empty($error['detail4'])?'':'class="error"'; ?>>
        <td>Dosificación</td>
        <td class="mce"><textarea name="r[detail4]" class="html"><?php echo empty($product['detail4'])?'':$product['detail4']; ?></textarea></td>
      </tr>

      <tr>
        <td>Composición:</td>
        <td class="composicion">
          <table>
          
            <?php foreach($composicion as $c): ?>
            <tr>
              <td>
                Producto: <input type="text" name="c[producto][]" value="<?php echo($c['titulo']); ?>"> 
                Cantidad:<input class="composicion" type="text" name="c[cantidad][]" value="<?php echo($c['descripcion']); ?>">
              </td>
            </tr>
            <?php endforeach; ?>
            
            <tr>
              <td>Producto: <input type="text" name="c[producto][]"> Cantidad:<input class="composicion" type="text" name="c[cantidad][]"></td>
            </tr>
            
            <tr style="display: none;" class="xcomp">
              <td>Producto: <input type="text" name="c[producto][]"> Cantidad:<input class="composicion" type="text" name="c[cantidad][]"></td>
            </tr>
            
          </table>
          <a href="javascript:void(0);" id="mas_composicion">Agregar más</a>
        </td>
      </tr>


      
      <tr>
        <td>Estado</td>
        <td>
          <select name="r[status]">
            <option value="1"<?php echo empty($product['status'])?'':' selected="selected"'; ?>>Publicado</option>
            <option value="0"<?php echo (!$creating) && empty($product['status'])?' selected="selected"':''; ?>>No publicado</option>
          </select>
        </td>
      </tr>
            
      <tr>
        <td></td>
        <td><input type="submit" value="Guardar"></td>
        <td></td>
      </tr>      
      
    </table>
    </form>
    </div>
</div>
<div class="admin_links">
<?php AdminHelper::userBox(1); ?><br/><br/>
<h3>Secciones</h3>
<?php AdminHelper::links(1); ?>
</div>
<script type="text/javascript">
  $(function(){
    $('.page_selector').change(function(){ top.location.href = "users/list/page_"+$(this).val(); });
	$('textarea.html').tinymce({
		// Location of TinyMCE script
		script_url : '<?php echo Config::get('base_url', '/');?>js/tinymce/tiny_mce.js',

		// General options
		theme : "advanced",
		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

		// Theme options
	//	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull", //,styleselect,formatselect,fontselect,fontsizeselect",
	//	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo",
    //    theme_advanced_buttons3 : "link,unlink,anchor,image,cleanup,help,|,forecolor,backcolor",
		//theme_advanced_buttons4 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		//theme_advanced_buttons5 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		
        theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
        
//        invalid_elements : "h1,h2,h3,h4,address,pre",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
    window.xcomp = $('.xcomp');
    $('#mas_composicion').click(function(){
        var clone = window.xcomp.clone();
        window.xcomp.before(clone);
        clone.show();
    });
  });
</script>